<html>
<body>
<p>Test that a cross-origin chain of redirects to a server that responds is indistinguishable from one that does not. Should say PASS:</p>
<pre id='console'></pre>
<script type="text/javascript">
    if (window.testRunner)
        testRunner.dumpAsText();

    function log(message)
    {
        document.getElementById('console').appendChild(document.createTextNode(message + "\n"));
    }

    var xhr;
    var logExisting;
    var logMissing;

    xhr = new XMLHttpRequest;
    xhr.onreadystatechange = function() { log("onreadystatechange " + xhr.readyState) }
    xhr.onload = function() { log("onload") }
    xhr.onloadstart = function() { log("onloadstart") }
    xhr.onprogress = function() { log("onprogress") }
    xhr.onerror = function() { log("onerror") }
    try {
        xhr.open("GET", "resources/redirect.php?url=http://localhost:8000/xmlhttprequest/resources/redirect.php?url=/xmlhttprequest/resources/reply.xml", false);
        xhr.send();
    } catch (ex) {
        log("Exception thrown: " + ex.name);
    }

    if (xhr.responseText.length)
        alert("FAIL: Response is not empty, " + xhr.responseText);

    logExisting = document.getElementById('console').innerHTML;
    document.getElementById('console').innerHTML = "";

    xhr = new XMLHttpRequest;
    xhr.onreadystatechange = function() { log("onreadystatechange " + xhr.readyState) }
    xhr.onload = function() { log("onload") }
    xhr.onloadstart = function() { log("onloadstart") }
    xhr.onprogress = function() { log("onprogress") }
    xhr.onerror = function() { log("onerror"); }
    try {
        xhr.open("GET", "resources/redirect.php?url=http://localhost:7/", false); // A port that will likely refuse the connection.
        xhr.send();
    } catch (ex) {
        log("Exception thrown: " + ex.name);
    }

    if (xhr.responseText.length)
        alert("FAIL: Response is not empty, " + xhr.responseText);

    logMissing = document.getElementById('console').innerHTML;
    document.getElementById('console').innerHTML = "";
    
    if (logMissing == logExisting)
        log("PASS");
    else {
        log("FAIL. Responding server:");
        document.getElementById('console').innerHTML += logExisting;
        log("Non-existent server:");
        document.getElementById('console').innerHTML += logMissing;
    }
</script>
</body>
</html>
